package com.ooono.factorytest.items;

import android.content.Intent;
import android.os.Bundle;

import androidx.annotation.Nullable;
import androidx.appcompat.widget.SwitchCompat;

import com.ooono.factorytest.R;
import com.ooono.factorytest.base.BaseActivity;

import mcs8.mdm.PolicyManager;

public class LedTestActivity extends BaseActivity {

    public static final String KEY = "led";

    @Override
    public int getTestTitle() {
        return R.string.test_item_led;
    }

    @Override
    public String getTestKey() {
        return KEY;
    }

    @Override
    public int getContentLayout() {
        return R.layout.content_led_test;
    }

    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
    }

    @Override
    public void initViews() {
        SwitchCompat redLedTestSwitch = findViewById(R.id.led_test_switch_red);
        redLedTestSwitch.setOnCheckedChangeListener((buttonView, isChecked) -> PolicyManager.redLightEnable(isChecked));
        SwitchCompat blueLedTestSwitch = findViewById(R.id.led_test_switch_blue);
        blueLedTestSwitch.setOnCheckedChangeListener((buttonView, isChecked) -> PolicyManager.blueLightEnable(isChecked));
        SwitchCompat greenLedTestSwitch = findViewById(R.id.led_test_switch_green);
        greenLedTestSwitch.setOnCheckedChangeListener((buttonView, isChecked) -> PolicyManager.greenLightEnable(isChecked));
        SwitchCompat strobeLedTestSwitch = findViewById(R.id.led_test_switch_strobe_led);
        strobeLedTestSwitch.setOnCheckedChangeListener((buttonView, isChecked) -> PolicyManager.strobeLightEnable(isChecked));
        SwitchCompat laserLedTestSwitch = findViewById(R.id.led_test_switch_laser_led);
        laserLedTestSwitch.setOnCheckedChangeListener((buttonView, isChecked) -> PolicyManager.laserLightEnabled(isChecked));
        SwitchCompat irTestSwitch = findViewById(R.id.led_test_switch_ir);
        irTestSwitch.setOnCheckedChangeListener((buttonView, isChecked) -> PolicyManager.irLedEnable(isChecked));
        SwitchCompat flashTestSwitch = findViewById(R.id.led_test_switch_flash);
        flashTestSwitch.setOnCheckedChangeListener((buttonView, isChecked) -> PolicyManager.openFlash(isChecked));
        SwitchCompat pilotTestSwitch = findViewById(R.id.led_test_switch_pilot);
        pilotTestSwitch.setOnCheckedChangeListener((buttonView, isChecked) -> PolicyManager.pilotLampOpen(isChecked));
        SwitchCompat irCutTestSwitch = findViewById(R.id.led_test_switch_ir_cut);
        irCutTestSwitch.setOnCheckedChangeListener((buttonView, isChecked) -> PolicyManager.irCutEnable(isChecked));
    }

    @Override
    protected void onStop() {
        closeAllLed();
        if (mHandler != null) {
            mHandler.removeCallbacksAndMessages(null);
        }
        super.onStop();
    }

    private void closeAllLed() {
        PolicyManager.redLightEnable(false);
        PolicyManager.blueLightEnable(false);
        PolicyManager.greenLightEnable(false);
        PolicyManager.strobeLightEnable(false);
        PolicyManager.laserLightEnabled(false);
        PolicyManager.irLedEnable(false);
        PolicyManager.openFlash(false);
        PolicyManager.pilotLampOpen(false);
        PolicyManager.irCutEnable(false);
    }
}